package com.cyt.web.controller.work.kwmanagement;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.StringUtils;
import com.cyt.sys.util.EasyPoiUtil;
import com.cyt.work.association.model.vo.WxAssociationNewStuExportVo;
import com.cyt.work.kwmanagement.model.po.KwStudentMessage;
import com.cyt.work.kwmanagement.model.vo.*;
import com.cyt.work.kwmanagement.service.KwStudentMessageService;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 考务学生表-考务学生表控制层
 *
 * @author han jun
 * @date 2019-11-26 11:24:38
 */
@RestController
public class KwStudentMessageController extends BaseController {

    @Resource
    private KwStudentMessageService kwStudentMessageService;

    /**
     * 统一跳转
     *
     * @param model 数据模型
     * @return Model
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @RequestMapping("/work/kwmanagement/kwstudentmessage/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 分页查询
     *
     * @param kwStudentMessageVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/page", method = RequestMethod.POST)
    public ReturnResult page(KwStudentMessageVo kwStudentMessageVo, int page, int limit) {
        return kwStudentMessageService.pageNew(kwStudentMessageVo, page, limit);
    }


    /**
     * 分页查询
     *
     * @param kwStudentMessageVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/pageNew", method = RequestMethod.POST)
    public ReturnResult pageNew(KwStudentMessageVo kwStudentMessageVo, int page, int limit) {
        return kwStudentMessageService.pageNewOther(kwStudentMessageVo, page, limit);
    }



    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("/work/kwmanagement/kwstudentmessage/kwStudentMessageEdit");
        if (StringUtils.isNotBlank(id)) {
            view.addObject(kwStudentMessageService.selectByPrimaryKey(id));
        }
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param kwStudentMessageVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, KwStudentMessageVo kwStudentMessageVo) {
        return kwStudentMessageService.addOrUpdate(kwStudentMessageVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param kwStudentMessageVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, KwStudentMessageVo kwStudentMessageVo) {
        return kwStudentMessageService.remove(kwStudentMessageVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param kwStudentMessageVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, KwStudentMessageVo kwStudentMessageVo) {
        return kwStudentMessageService.delete(kwStudentMessageVo, acceptCurrentUser(request));
    }

    /**
     * 导出考务的学生信息模板
     * @param response
     * @author hanjun
     * @date 2019/9/3 13:43
     */
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/export")
    public void exportExcel(HttpServletResponse response) {
        List<KwStudentMessageExportVo> list = new ArrayList<>();
        list.add(new KwStudentMessageExportVo("C20150126", "崔必明","18019933806"));
        list.add(new KwStudentMessageExportVo("C20150127", "赵军","18019933805"));
        // 导出操作
        EasyPoiUtil.exportExcel(list, "学生信息", "学生信息", KwStudentMessageExportVo.class, "学生信息.xls", response);
    }

    /**
     * 导入社团人员，主要需要保存到学校用户表
     * @param file
     * @param request
     * @author hanjun
     * @date 2019/9/3 13:33
     */
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/importExcel", method = RequestMethod.POST)
    public ReturnResult importExcel(MultipartFile file, HttpServletRequest request, String ksId, String applyId) {
        return kwStudentMessageService.importExcel(file,ksId,acceptCurrentUser(request),applyId);
    }

    /**
     * 导入学生列表
     * @param file
     * @param request
     * @author hanjun
     * @date 2019/9/3 13:33
     */
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/importStudnetScoreExcel", method = RequestMethod.POST)
    public ReturnResult importStudnetScoreExcel(MultipartFile file, HttpServletRequest request, String ksId, String applyId) {
        return kwStudentMessageService.importExcelStudentScore(file,ksId,acceptCurrentUser(request),applyId);
    }



    /**
     * 统计某个考务学生总人数
     *
     * @param request
     * @param kwStudentMessageVo
     * @return ReturnResult
     * @author Jun Han
     * @date 2019/12/4 15:36
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/staticStudent", method = RequestMethod.POST)
    public ReturnResult staticStudent(HttpServletRequest request, KwStudentMessageVo kwStudentMessageVo) {
        List<KwStudentMessage> list = kwStudentMessageService.listExample(kwStudentMessageVo);
        return  new ReturnResult(list);
    }



    /**
     * 分配学生考场的情况
     *
     * @param request
     * @param kwStudentMessageVo
     * @return ReturnResult
     * @author Jun Han
     * @date 2019/12/4 15:36
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "分配学生", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/studentDistribution", method = RequestMethod.POST)
    public ReturnResult studentDistribution(HttpServletRequest request, KwStudentMessageVo kwStudentMessageVo) {
        ReturnResult returnResult = kwStudentMessageService.startDistributeStudent(kwStudentMessageVo,acceptCurrentUser(request));
        return  returnResult;
    }

    /**
     * 分页查询
     *
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/getStudnetAllstatic", method = RequestMethod.POST)
    public ReturnResult getStudnetAllstatic(int page, int limit) {
        return kwStudentMessageService.getAllStudentStatic(page, limit);
    }



    /**
     *
     *
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author han jun
     * @date 2019-11-26 11:24:38
     */
    @BaseLog(module = "考务学生表", classz = "考务学生表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/getAllStudentSign", method = RequestMethod.POST)
    public ReturnResult getAllStudentSign(KwStudentMessageVo kwStudentMessageVo,int page, int limit) {
        return kwStudentMessageService.getAllStudentSign(kwStudentMessageVo,page, limit);
    }


    /**
     * 学生考试情况统计
     * @param response
     * @author hanjun
     * @date 2019/9/3 13:43
     */
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/exportksStudnet")
    public void exportksStudnet(HttpServletResponse response) {
        List<KwStudentStaticVo> list = kwStudentMessageService.getAllKsStudent();
        // 导出操作
        EasyPoiUtil.exportExcel(list, "学生考试情况统计", "学生考试情况统计", KwStudentStaticVo.class, "学生考试情况统计.xls", response);
    }


    /**
     * 导出某场考试所有学生分配情况
     * @param response
     * @author hanjun
     * @date 2019/9/3 13:43
     */
    @RequestMapping(value = "/work/kwmanagement/kwstudentmessage/exportStudnetStri")
    public void exportStudnetStri(HttpServletResponse response,KwStudentMessageVo kwStudentMessageVo) {
        List<KwStudentExportVo> list = kwStudentMessageService.exPortStu(kwStudentMessageVo);
        // 导出操作
        EasyPoiUtil.exportExcel(list, "学生分配情况", "学生分配情况", KwStudentExportVo.class, "学生分配情况.xls", response);
    }






}